package com.fudan.adse.controller;

import com.fudan.adse.api.CommonResult;
import com.fudan.adse.domain.dto.RowPieceDTO;
import com.fudan.adse.domain.po.FilmRowPiece;
import com.fudan.adse.service.RowPieceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * 排片管理控制器
 * @author Jerry Zhang
 * create: 2022-11-23 09:49
 */
@RestController
@RequestMapping("/api/v1/rms")
public class RowPieceController {
    @Autowired
    private RowPieceService rowPieceService;

    /**
     * 新增排片
     * @param rowPiece
     * @return
     */
    @PostMapping(value = "/row-piece")
    public CommonResult<FilmRowPiece> addRowPiece(@Validated @RequestBody RowPieceDTO rowPiece) {
        return CommonResult.success(rowPieceService.addRowPiece(rowPiece));
    }

    @PutMapping(value = "/row-piece")
    public CommonResult<FilmRowPiece> updateRowPieceDetail(@Validated @RequestBody RowPieceDTO rowPiece) {
        return CommonResult.success(rowPieceService.updateRowPiece(rowPiece));
    }

    @DeleteMapping(value = "/row-piece")
    public CommonResult<Object> deleteRowPiece(@NotBlank @RequestParam("rowPieceId") Integer rowPieceId) {
        rowPieceService.deleteRowPiece(rowPieceId);
        return CommonResult.success(null);
    }
}
